<?php
/**
 * CDR 消息
 *
 *
 */
 namespace OM\Dev;

use OM\Lib\Apihelper;

 class Cdr
 {
 	private  $m_id ; //cdr编号,话单id,
 	public $m_callid; //通话的相对唯一标识符
 	public $m_visitor ; //int	来电的编号 或者去电的编号，内部分机通话记录无此字段。
 	public $m_outer;//
 	public $m_type;//IN（打入）/OU（打出）/FI（呼叫转移入）/FW（呼叫转移出）/LO（内部通话）/CB（双向外呼）
 	public $m_tmstart;//IP（IP中继）/XO（模拟中继）/IC（内部）/OP（总机）
 	public $m_route;//IP（IP中继）/XO（模拟中继）/IC（内部）/OP（总机）
 	public $m_cpn;//主叫号码
 	public $m_cdpn;//被叫号码
 	public $m_tmend;//呼叫结束时间，即通话的一方挂断的时间
 	public $m_duration;//通话时长，值为0说明未接通。
 	public $m_trunknumber;//该路通话所经过的中继号码
 	public $m_recording; /*录音文件的相对保存路径，格式：年月日/录音文件
							录音文件的命名格式：
							1.主叫号码_被叫号码_年月日-时分秒_通话的相对唯一标识符.文件格式
							2.主叫号码_被叫号码_年月日-时分秒_通话的相对唯一标识符_cd.文件格式
							3.主叫号码_被叫号码_年月日-时分秒_通话的相对唯一标识符_cg.文件格式
							cg 为主叫录音，cd 为被叫录音。*/
	public $m_area;/*呼叫电话号码归属地*/

 	public $m_extid; //关联分机号

 	public function __construct( )
 	{
 	}

	 	/** cdr消息示例
		 <Cdr id="value">
		  <callid> value </callid>
		  <visitor|outer id=" value " />
		  <TimeStart> value </TimeStart>
		  <Type> value </Type>
		  <Route> value </Route>
		  <CPN> value </CPN>
		  <CDPN> value </CDPN>
		  <TimeEnd> value </TimeEnd>
		  <Duration> value </Duration>
		  <TrunkNumber> value </TrunkNumber>
		  <Recording> value </Recording>
		</Cdr>
	   */

 	public function xmlInit( $xml ){

 		$this->m_id = isset( $xml['id'] ) ? strval( $xml['id'] ) :'';
 		$this->m_callid = isset( $xml->callid )  ? intval( $xml->callid ) :false;
 		$this->m_visitor = isset( $xml->visitor ) ? intval($xml->visitor['id'] ): null;
 		$this->m_outer = isset( $xml->outer ) ? intval($xml->outer['id'] ): null;
 		$this->m_type = isset( $xml->Type ) ? strval( $xml->Type ) : null;
 		$this->m_tmstart = isset( $xml->TimeStart ) ? strval($xml->TimeStart) : null;
 		$this->m_route =  isset( $xml->Route ) ? strval($xml->Route) : null;
 		$this->m_cpn =  isset( $xml->CPN ) ? strval($xml->CPN) : null;
 		$this->m_cdpn =  isset( $xml->CDPN ) ? strval($xml->CDPN) : null;
 		$this->m_tmend =  isset( $xml->TimeEnd ) ? strval($xml->TimeEnd) : null;
 		$this->m_duration =  isset( $xml->Duration ) ? strval($xml->Duration) : null;
 		$this->m_trunknumber =  isset( $xml->TrunkNumber ) ? strval($xml->TrunkNumber) : null;
 		$this->m_recording = isset( $xml->Recording ) ? strval( $xml->Recording ) :null;
 		if( 'IN' == $this->m_type || 'FI' == $this->m_type ){
 			$this->m_extid = $this->m_cdpn;
 			$this->m_cpn = Apihelper::phone( $this->m_cpn );
 		}
 		elseif( 'CB' != $this->m_type ){
 			$this->m_extid = $this->m_cpn;
 			$this->m_cdpn = Apihelper::phone( $this->m_cdpn );
 		}
 	}

 	public function  v2arr(){
 		return get_object_vars( $this );
 	}
 }
?>